<template>
  <view class="disFlxAC gap-8 flexEnd" @click="open">
    <text class="fz-14 linh-20" style="color: #999996">
      {{ text }}
    </text>
    <text class="ali-icon icon-you1 fz-16" style="color: #999996"></text>
  </view>
  <ActionSheet
    v-model="show"
    :itemList="itemList"
    :border="false"
    @change="handleChange"
  ></ActionSheet>
</template>
<script setup lang="ts">
  import ActionSheet, { type ActionSheetItem } from '@/components/ActionSheet/index.vue';
  import { ShowTypeEnum, PromotionTypeEnum } from '@/enums/businessOpportunitiesEnum';
  import { propTypes } from '@/utils/propTypes';
  import { computed, ref, type PropType, watch } from 'vue';
  const props = defineProps({
    modelValue: {
      type: Number,
      default: undefined,
    },
    promotionType: Number as PropType<PromotionTypeEnum>,
    promotionFlag: propTypes.bool.def(false),
  });

  const emits = defineEmits(['update:modelValue']);

  const show = ref(false);

  const itemList = ref<ActionSheetItem[]>([
    {
      text: '全部人可见',
      value: ShowTypeEnum.AllVisible,
      des: '所有人都可查看本供需',
      disabled: false,
    },
    {
      text: '仅会员可见',
      value: ShowTypeEnum.MemberOnly,
      des: '拥有会员身份才可以查看本供需',
      disabled: false,
    },
    {
      text: '私密（仅分享可见）',
      value: ShowTypeEnum.PrivateShared,
      des: '不对外展示，可分享（申请跨会推广后不可设置私密）',
      disabled: false,
    },
  ]);

  watch(
    () => [props.promotionType, props.promotionFlag],
    () => {
      itemList.value[2].disabled =
        props.promotionType == PromotionTypeEnum.CrossConference || props.promotionFlag;
      if (itemList.value[2].disabled) {
        emits('update:modelValue', itemList.value[0].value);
      }
    },
  );

  const text = computed(() => {
    return itemList.value.find((item) => item.value == props.modelValue)?.text;
  });

  const open = () => {
    show.value = true;
  };

  const handleChange = (index: number) => {
    emits('update:modelValue', itemList.value[index].value);
  };
</script>
<style lang="scss" scoped></style>
